Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
Writing internal procedures
Now it’s time to write the calcDays procedure. Put it at the end of
h-CustSample.p, following all the code you’ve written so far.Each internal procedure starts with a header statement, which is just the keyword
PROCEDUREfollowed by the internal procedure name and a colon.Following this you need to define any parameters the procedure uses. The syntax for this is very similar to the syntax for the
DEFINE VARIABLEstatement. In place of the keywordVARIABLE, use the keywordPARAMETER, and precede this with the parameter type—INPUT,OUTPUT, orINPUT-OUTPUT. Note that the keywordINPUTis not optional in parameter definitions. Here’s the declaration for thecalcDaysprocedure and its parameters. The parameter names start with the letter p to help identify them, followed by a prefix that identifies the data type asDATEorINTEGER:
Now you can write 4GL statements exactly as you can for an external procedure. If you want to have variables in the subprocedure that aren’t needed elsewhere, then define them following the parameter definitions. Otherwise you can refer freely to variables that are defined in the external procedure itself. You’ll take a much closer look at variable scope and other such topics later. Be cautious when you use variables that are defined outside a procedure unless you have a good reason for using them, because they compromise the modularity and reusability of your code. For example, if you pull your procedures apart later and put the
calcDaysprocedure somewhere else, it might break if it has a dependency on something declared outside of it. For this reason, you pass the calculated number of days back as anOUTPUTparameter, even though you could refer to the variable directly.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |